package biz

import (
	"github.com/silenceper/wechat/v2"
	"github.com/silenceper/wechat/v2/cache"
	"github.com/silenceper/wechat/v2/officialaccount"
	"github.com/silenceper/wechat/v2/officialaccount/config"
	"github.com/silenceper/wechat/v2/officialaccount/message"
	"github.com/silenceper/wechat/v2/officialaccount/oauth"
)

var WxOfficial *officialaccount.OfficialAccount
var WxOauth *oauth.Oauth

func init() {
	wxcache := cache.NewMemory()
	cfg := &config.Config{
		AppID:     "wx8d9d64c4a15408e9",
		AppSecret: "8efb54421b4f23c9c13800292b194384",
		Cache:     wxcache,
	}
	WxOfficial = wechat.NewWechat().GetOfficialAccount(cfg)
	WxOauth = WxOfficial.GetOauth()
}

// 发送客服文本消息
func SendTextMessage(openid, text string) error {
	m := &message.CustomerMessage{
		ToUser:  openid,
		Msgtype: message.MsgTypeText,
		Text: &message.MediaText{
			Content: text,
		},
	}
	err := WxOfficial.GetCustomerMessageManager().Send(m)
	return err
}
